#include <cstdio>
//TODO:

typedef long long ll;
const int N = 1000010;
int m, t, a, b, ans;
ll sum, flag[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("T1.in", "r", stdin);
	freopen("T1.out", "w", stdout);
#endif
#endif

	scanf("%d", &m);
	for (register int i = 1; i <= m; ++i) {
		scanf("%d%d", &t, &a);
		sum += flag[i];
		switch (t) {
		case 1:
			sum += a;
			break;
		case 2:
			if (sum >= a) {
				sum -= a;
			} else {
				++ans;
			}
			break;
		case 3:
			scanf("%d", &b);
			sum -= a;
			flag[b] += a;
			break;
		}
	}
	printf("%d", ans);
	return 0;
}